
object ScalaType {

    def main(args: Array[String]): Unit = {
        var element0: String = "element0"
        var element1: String = "element1"

        testArray(element0, element1)

        testList(element0, element1)

    }


    def testArray(element0: String, element1: String): Unit = {
        var array1 = new Array[Double](2)
        var array2 = Array(element0, element1)


        var length: Int = array1.length
        // @scala.inline:内联（替换）
        // var size: Int = array2.size

        // 下标从0开始
        array1(0) = 0.2468
        array1(1) = 1.3579

        // 遍历
        for (value <- array2) println(value)
        for (index <- array2.indices) println(array2(index))
        // for (index <- 0 until array2.length) println(array2(index))
        // for (index <- 0 to array2.length - 1) println(array2(index))
        println("-" * 100)

        // 聚合函数
        println(array1.sum)
        println("-" * 100)
        println(array1.min)
        println("-" * 100)
        println(array1.max)
        println("-" * 100)

        for (value <- array1.sorted) println(value)
        println("-" * 100)
        for (value <- array1.reverse) println(value)
        println("-" * 100)



    }


    def testList(element0: String, element1: String): Unit = {
        // 空列表
        var list0 = Nil
        var list1 = element0 :: element1 :: Nil
        var list2 = List(element0, element1)

        // 迭代器
        var iterator =  list1.iterator
        while (iterator.hasNext){
            println(iterator.next)
        }



    }

    //
    def testSet(): Unit = {

    }

    def testMap(): Unit = {
        var key:String = "key"
        var value:String = "value"
        var map = Map(key-> value)
        // 没有key返回Null
        value = map(key)
        // 没有键Key返回默认值"Null"
        value = map.getOrElse("Key", "Null")
        var keys = map.keys
        var values = map.values


        // 遍历
        for((k, v) <- map) println(s"k:${k}, v:${v}")

    }


}
